package com.ruijixiang.leetcode.everyday.leetcode2024.leetcode202409;

public class leetcode20240908 {
    public int[] sortedSquares(int[] nums){
        int left=0,right=nums.length-1;
        int[] res=new int[nums.length];
        int idx=nums.length-1;
        while(left<=right){
            if(Math.abs(nums[left])>Math.abs(nums[right])){
                res[idx]=Math.abs(nums[left])*Math.abs(nums[left]);
                left++;
            }else{
                res[idx]=Math.abs(nums[right])*Math.abs(nums[right]);
                right--;
            }
            idx--;
        }
        return res;
    }
}
